﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DingY.DB;

namespace DotNet.WinUI.Customer
{
    public partial class FrmIndustryList : BaseForm
    {
        public FrmIndustryList()
        {
            InitializeComponent();
        }

        private void LoadIndustry()
        {
            string _Sql = @"SELECT IndustryID, Name AS 行业名称, Depict AS 说明
                FROM Industry ";

            FillDataToGridView(dgDict, _Sql);
            dgDict.Columns[0].Visible = false;
        }

        private void DelIndustry()
        {
            if (dgDict.SelectedRows.Count <= 0)
            {
                ShowMsg("未选择数据信息！");
                return;
            }

            if (dgDict.SelectedCells[0].Value.ToString() == "")
            {
                ShowMsg("未选择有效数据信息！");
                return;
            }

            if (ShowQuestionMsg(string.Format("确认删除行业信息【 {0} 】吗", dgDict.SelectedCells[1].Value.ToString())) == DialogResult.OK)
            {
                string sql = @"DELETE FROM Industry WHERE IndustryID = '{0}' ";
                sql = string.Format(sql, dgDict.SelectedCells[0].Value.ToString());

                SqlDB objSqlDB = new SqlDB();
                int i = objSqlDB.ExecuteSql(sql);
                if (i >= 1)
                {
                    ShowMsg("成功删除数据信息！");
                }
            }
        }

        private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            switch (e.ClickedItem.Text)
            {
                case "新增":
                    FrmIndustryEdit objFrmIndustryEdit = new FrmIndustryEdit("0");
                    objFrmIndustryEdit.ShowDialog();

                    LoadIndustry();
                    break;
                case "关闭":
                    Close();
                    break;
                case "删除":
                    DelIndustry();
                    break;
                case "编辑":
                    dgDict_DoubleClick(sender, e);
                    break;
            }
            LoadIndustry();
        }

        private void dgDict_DoubleClick(object sender, EventArgs e)
        {
            if (dgDict.SelectedRows.Count <= 0)
            {
                ShowMsg("未选择数据信息！");
                return;
            }

            if (dgDict.SelectedCells[0].Value.ToString() == "")
            {
                ShowMsg("未选择有效数据信息！");
                return;
            }

            FrmIndustryEdit objFrmIndustryEdit = new FrmIndustryEdit(dgDict.SelectedCells[0].Value.ToString());
            objFrmIndustryEdit.ShowDialog();
        }

        private void FrmIndustryList_Load(object sender, EventArgs e)
        {
            LoadIndustry();
        }
    }
}